package cn.com.bluemoon.daps.api.model.factory;

import cn.com.bluemoon.daps.api.model.RemoteModelGroupService;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.common.toolkit.FeignClientTools;
import cn.com.bluemoon.daps.model.entity.DapDataModelGroup;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class RemoteModelGroupServiceFallbackFactory implements FallbackFactory<RemoteModelGroupService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteModelGroupServiceFallbackFactory.class);

    @Override
    public RemoteModelGroupService create(Throwable throwable) {
        log.error("分组服务调用失败:{}", throwable.getMessage());
        return new RemoteModelGroupService() {

            @Override
            public ResultBean<List<DapDataModelGroup>> modelGroups(String modelId) {
                return FeignClientTools.INSTANCE.errorMsgCatch(throwable, ServiceNameConstants.DapsApiModel.PROD_SERVICE, "获取模型默认分组失败！");
            }
        };
    }
}
